// 执行FFT并返回频谱
vector<pair<double, double>> perform_fft(const vector<double>& signal, double sampling_rate) {
    int N = signal.size();
    vector<pair<double, double>> spectrum;

    for (int k = 0; k < N / 2; ++k) {
        double real_part = 0.0;
        double imag_part = 0.0;
        for (int n = 0; n < N; ++n) {
            double angle = 2 * PI * k * n / N;
            real_part += signal[n] * cos(angle);
            imag_part -= signal[n] * sin(angle);
        }
        double magnitude = sqrt(real_part * real_part + imag_part * imag_part);
        double frequency = k * sampling_rate / N;
        spectrum.emplace_back(frequency, magnitude);
    }

    return spectrum;
}